package com.restaurant.application.shoplist.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;
import com.nebutown.generation.basictype.UIDLists;

import java.util.List;

public class ShopListData implements PickableBean {

    public static final String FN_SHOPS = "shops";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_SHOPS);
    
    private UIDLists shops;

    public ShopListData(UIDLists shops) {
        setShops(shops);
    }

    public ShopListData() {
    }

    public ShopListData duplicate() {
        ShopListData result = new ShopListData();
        result.shops = this.shops == null ? null : this.shops.duplicate();
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public UIDLists getShops() {
        if (shops == null) {
            shops = new UIDLists();
        }
        return shops;
    }

    public void setShops(UIDLists value) {
        this.shops = value;
    }

    public ShopListData withShops(UIDLists value) {
        setShops(value);
        return this;
    }

    public ShopListData withShops(UIDLists value, UIDLists defaultValue) {
        setShops(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "shops":
                return getShops();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ShopListData)) return false;
        return signature().equals(((ShopListData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean ShopListData has no signature defined, no hash code or equals possible.");
    }
}
